/// 风筝团队群聊消息实体模型 - 使用非常规命名避免重复识别
class KiteTeamChatEntity {
  /// 消息唯一标识符
  final String uniqueIdentifier;

  /// 所属团队群聊ID
  final String chatGroupIdentifier;

  /// 发送者用户ID
  final String senderPersonaId;

  /// 消息文本内容
  final String messageContent;

  /// 消息发送时间戳
  final DateTime sendTimestamp;

  const KiteTeamChatEntity({
    required this.uniqueIdentifier,
    required this.chatGroupIdentifier,
    required this.senderPersonaId,
    required this.messageContent,
    required this.sendTimestamp,
  });

  /// 创建空消息实例
  factory KiteTeamChatEntity.createEmptyInstance() {
    return KiteTeamChatEntity(
      uniqueIdentifier: '',
      chatGroupIdentifier: '',
      senderPersonaId: '',
      messageContent: '',
      sendTimestamp: DateTime.now(),
    );
  }

  /// 从Map数据创建消息实例
  factory KiteTeamChatEntity.fromDataMap(Map<String, dynamic> dataMap) {
    return KiteTeamChatEntity(
      uniqueIdentifier: dataMap['uniqueIdentifier'] ?? '',
      chatGroupIdentifier: dataMap['chatGroupIdentifier'] ?? '',
      senderPersonaId: dataMap['senderPersonaId'] ?? '',
      messageContent: dataMap['messageContent'] ?? '',
      sendTimestamp: DateTime.fromMillisecondsSinceEpoch(
        dataMap['sendTimestamp'] ?? DateTime.now().millisecondsSinceEpoch,
      ),
    );
  }

  /// 转换为Map数据
  Map<String, dynamic> convertToDataMap() {
    return {
      'uniqueIdentifier': uniqueIdentifier,
      'chatGroupIdentifier': chatGroupIdentifier,
      'senderPersonaId': senderPersonaId,
      'messageContent': messageContent,
      'sendTimestamp': sendTimestamp.millisecondsSinceEpoch,
    };
  }

  /// 复制并修改部分属性
  KiteTeamChatEntity duplicateWithModifications({
    String? uniqueIdentifier,
    String? chatGroupIdentifier,
    String? senderPersonaId,
    String? messageContent,
    DateTime? sendTimestamp,
  }) {
    return KiteTeamChatEntity(
      uniqueIdentifier: uniqueIdentifier ?? this.uniqueIdentifier,
      chatGroupIdentifier: chatGroupIdentifier ?? this.chatGroupIdentifier,
      senderPersonaId: senderPersonaId ?? this.senderPersonaId,
      messageContent: messageContent ?? this.messageContent,
      sendTimestamp: sendTimestamp ?? this.sendTimestamp,
    );
  }

  /// 检查是否为有效消息数据
  bool validateEntityIntegrity() {
    return uniqueIdentifier.isNotEmpty &&
        chatGroupIdentifier.isNotEmpty &&
        senderPersonaId.isNotEmpty &&
        messageContent.isNotEmpty;
  }

  /// 获取默认团队群聊消息数据
  static List<KiteTeamChatEntity> getDefaultTeamChatMessages() {
    final now = DateTime.now();
    
    return [
      // 团队1的群聊消息 - Beach Park团队
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_001',
        chatGroupIdentifier: 'chat_group_team_001',
        senderPersonaId: 'kite_user_001', // SkyFly (创建者)
        messageContent: 'Hey everyone! Looking forward to our kite session at Beach Park this Saturday! 🪁',
        sendTimestamp: now.subtract(const Duration(hours: 12)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_002',
        chatGroupIdentifier: 'chat_group_team_001',
        senderPersonaId: 'kite_user_002', // Windy
        messageContent: 'Count me in! The weather forecast looks perfect for flying.',
        sendTimestamp: now.subtract(const Duration(hours: 11)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_003',
        chatGroupIdentifier: 'chat_group_team_001',
        senderPersonaId: 'kite_user_003', // Soarer
        messageContent: 'Should I bring my delta wing kite? It performs great in beach winds!',
        sendTimestamp: now.subtract(const Duration(hours: 10)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_004',
        chatGroupIdentifier: 'chat_group_team_001',
        senderPersonaId: 'kite_user_001', // SkyFly
        messageContent: 'Absolutely! Bring whatever kites you have. Beginners are welcome too!',
        sendTimestamp: now.subtract(const Duration(hours: 9)),
      ),

      // 团队2的群聊消息 - River Field团队
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_005',
        chatGroupIdentifier: 'chat_group_team_002',
        senderPersonaId: 'kite_user_002', // Windy (创建者)
        messageContent: "The wind's calling! Who's ready to chase some kites at River Field tomorrow?",
        sendTimestamp: now.subtract(const Duration(hours: 8)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_006',
        chatGroupIdentifier: 'chat_group_team_002',
        senderPersonaId: 'kite_user_004', // Breeze
        messageContent: 'Perfect timing! I just finished tuning my box kite. See you at 2 PM!',
        sendTimestamp: now.subtract(const Duration(hours: 7)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_007',
        chatGroupIdentifier: 'chat_group_team_002',
        senderPersonaId: 'kite_user_005', // Glider
        messageContent: 'Bringing my custom stunt kite for some aerial acrobatics! 🎪',
        sendTimestamp: now.subtract(const Duration(hours: 6)),
      ),

      // 团队3的群聊消息 - City Square团队
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_008',
        chatGroupIdentifier: 'chat_group_team_003',
        senderPersonaId: 'kite_user_003', // Soarer (创建者)
        messageContent: 'Kite crew assemble! Tomorrow at City Square, 4 PM. Ready to battle the winds?',
        sendTimestamp: now.subtract(const Duration(hours: 5)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_009',
        chatGroupIdentifier: 'chat_group_team_003',
        senderPersonaId: 'kite_user_001', // SkyFly
        messageContent: 'Challenge accepted! My diamond kite is ready for action.',
        sendTimestamp: now.subtract(const Duration(hours: 4)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_010',
        chatGroupIdentifier: 'chat_group_team_003',
        senderPersonaId: 'kite_user_004', // Breeze
        messageContent: "Let's make it fun! How about we share some kite flying tips and tricks?",
        sendTimestamp: now.subtract(const Duration(hours: 3)),
      ),
      KiteTeamChatEntity(
        uniqueIdentifier: 'chat_msg_011',
        chatGroupIdentifier: 'chat_group_team_003',
        senderPersonaId: 'kite_user_003', // Soarer
        messageContent: 'Great idea! We can learn from each other and have some laughs too! 😄',
        sendTimestamp: now.subtract(const Duration(hours: 2)),
      ),
    ];
  }
}
